package _interview150;

/**
 * 14. 最长公共前缀
 */
public class No14 {
    public String longestCommonPrefix(String[] strs) {
        int maxLen;
        label:
        for (maxLen = 0; maxLen < strs[0].length(); maxLen++) {
            String prefix = strs[0].substring(0, maxLen + 1);
            for (String str : strs) {
                if (str.length() < maxLen + 1 || !str.substring(0, maxLen + 1).equals(prefix)) break label;
            }
        }
        return strs[0].substring(0, maxLen);
    }
}
